package com.hhit.bigscreenbackmanage.util;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.util.StringUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;

/**
 * 日期工具类
 *
 * @Author Ivan
 * @Date 2019/3/26 16:05
 */
public class DateUtils {

	/**
	 * @param yyyy-MM-dd
	 * @return
	 */
	public static final String PATTERNA = "yyyy-MM-dd";
	/**
	 * @param yyyyMMdd
	 * @return
	 */
	public static final String PATTERNB = "yyyyMMdd";
	/**
	 * @param yyyy-MM-dd
	 *            HH-mm-ss
	 * @return
	 */
	public static final String PATTERNC = "yyyy-MM-dd HH-mm-ss";
	/**
	 * @param yyyy:MM:dd
	 *            HH:mm:ss
	 * @return
	 */
	public static final String PATTERND = "yyyy-MM-dd HH:mm:ss";
	/**
	 * @param yyyy-MM-dd
	 *            HH:mm:ss
	 * @return
	 */
	public static final String PATTERNE = "yyyy-MM-dd HH:mm";

	/**
	 * @param yyyyMMddHHmmss
	 * @return
	 */
	public static final String PATTERNF = "yyyyMMddHHmmss";

	public static final String PATTERNG = "yyyy年MM月dd日";

	/**
	 * @param yyyy-MM
	 * @return
	 */
	public static final String PATTERNH = "yyyy-MM";

	public static final String PATTERNI = "yyyyMM";

    public static final String PATTERNJ = "yyyy/MM/dd HH:mm:ss";

	/**
	 * 格式化日期为yyyy-MM-dd
	 *
	 * @param date
	 * @return
	 */
	public static String formateDate(Date date) {
		return dateToString(date, PATTERNA);
	}

	/**
	 * 格式化日期为yyyyMMdd
	 *
	 * @param date
	 * @return
	 */
	public static String formateDate(Date date, String pattern) {
		return dateToString(date, pattern);
	}

	public static String beforeMonth48(String month){
		DateTimeFormatter sdf =  DateTimeFormatter.ofPattern("yyyy-MM");
		YearMonth yearMonth = YearMonth.parse(month);
		return yearMonth.minus(1, ChronoUnit.MONTHS).toString();
	}

	/**
	 * 格式化日期为yyyy-MM
	 *
	 * @param date
	 * @return
	 */
	public static String formateYearAndMonth(Date date) {
		return dateToString(date, PATTERNH);
	}

	/**
	 * 取当天日期
	 * @return
	 */
	public static Date getDate() {
		return Calendar.getInstance().getTime();
	}

	/**
	 * 取指定年月日的日期,格式为yyyy-MM-dd,HH-mm-ss
	 * @param year
	 *  @param month
	 * @param day
	 * @return
	 */
	public static Date getDate(int year, int month, int day) {
		Calendar cal = Calendar.getInstance();
		cal.set(year, month - 1, day, 0, 0, 0);
		return cal.getTime();

	}

	/**
	 * 取指定年,月,日,小时,分,秒的时间
	 * @return
	 */
	public static Date getDate(int year, int month, int date, int hour, int mintue, int second) {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month - 1);
		cal.set(Calendar.DATE, date);
		cal.set(Calendar.HOUR_OF_DAY, hour);
		cal.set(Calendar.MINUTE, mintue);
		cal.set(Calendar.SECOND, second);
		return cal.getTime();
	}

	/**
	 * @param days=n
	 *            n为-,则取n天前,n为+,则取n天后的日期
	 * @param date
	 * @param days
	 * @return
	 */
	public static Date getSomeDaysBeforeAfter(Date date, int days) {
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		gc.add(5, days);
		gc.set(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH), gc.get(Calendar.DATE));
		return gc.getTime();
	}

	/**
	 * 取指定日期年份
	 * @param date
	 * @return
	 */
	public static int getDateYear(Date date) {

		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.YEAR);
	}

	/**
	 * 取指定日期月份
	 * @param date
	 * @return
	 */
	public static int getDateMonth(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.MONTH) + 1;
	}

	/**
	 * 取指定日期日份
	 * @param date
	 * @return
	 */
	public static int getDateDay(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.DATE);
	}

	/**
	 * 取指定日期小时
	 * @param
	 * @return
	 */
	public static int getDateHour(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.HOUR_OF_DAY);
	}

	/**
	 * 取指定日期分钟
	 * @param
	 * @return
	 */
	public static int getDateMinute(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.MINUTE);
	}

	/**
	 * 取指定日期的第二天的开始时间,小时,分,秒为00:00:00
	 * @param
	 * @return
	 */
	public static Date getNextDayStartTime(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return getNextDayStart(c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DATE));
	}

	/**
	 * 取指定年,月,日的下一日的开始时间,小时,分,秒为00:00:00
	 * 主要是用来取跨月份的日期
	 * @param
	 * @param
	 * @return
	 */
	public static Date getNextDayStart(int year, int monthIn, int date) {
		int month = monthIn - 1;
		boolean lastDayOfMonth = false;
		boolean lastDayOfYear = false;

		Calendar time = Calendar.getInstance();
		time.set(year, month, date, 0, 0, 0);
		Calendar nextMonthFirstDay = Calendar.getInstance();
		nextMonthFirstDay.set(year, month + 1, 1, 0, 0, 0);

		if (time.get(Calendar.DAY_OF_YEAR) + 1 == nextMonthFirstDay.get(Calendar.DAY_OF_YEAR)) {
			lastDayOfMonth = true;
		}


		if (time.get(Calendar.DAY_OF_YEAR) == time.getMaximum(Calendar.DATE)) {
			lastDayOfYear = true;
		}

		time.roll(Calendar.DATE, 1);

		if (lastDayOfMonth) {
			time.roll(Calendar.MONTH, 1);
		}

		if (lastDayOfYear) {
			time.roll(Calendar.YEAR, 1);
		}

		return time.getTime();
	}

	/**
	 * 取指定日期的下一日的时间
	 * @param
	 * @return
	 */
	public static Date nextDate(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DATE, 1);
		return cal.getTime();
	}

	/**
	 * 指定日期的下一日的开始时间,小时,分,秒为00:00:00
	 * @param
	 * @return
	 */
	public static Date getStartDateNext(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DATE, 1);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal.getTime();
	}

	/**
	 * 指定日期的开始时间,小时,分,秒为00:00:00
	 * @param
	 * @return
	 */
	public static Date getStartDateDay(Date date) {
		if (date == null) {
			return null;
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal.getTime();
	}

	/**
	 * 指定string日期的开始时间,小时,分,秒为00:00:00
	 * @param
	 * @return
	 */
	public static String getStartDateString(String date) {
		if (StringUtils.isEmpty(date)) {
			return null;
		}
		return date + " 00:00:00";
	}

	/**
	 * 指定日期的结束时间,小时,分,秒为23:59:59
	 * @param
	 * @return
	 */
	public static Date getEndDateDay(Date date) {
		if (StringUtils.isEmpty(date)) {
			return null;
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return cal.getTime();
	}

	/**
	 * 指定string日期的结束时间,小时,分,秒为23:59:59
	 * @param
	 * @return
	 */
	public static String getEndDateString(String date) {
		if (StringUtils.isEmpty(date)) {
			return null;
		}
		return date + " 23:59:59";
	}

	/**
	 * 将指定日期,以指定pattern格式,输出String值
	 * @param
	 * @return
	 */
	public static String dateToString(Date date, String pattern) {
		if (date == null) {
			return "";
		} else {
			SimpleDateFormat format = new SimpleDateFormat(pattern);
			return format.format(date);
		}
	}

	public static String dateToString1(Date date, String formatIn) {
		String format = formatIn;
		if (date == null) {
			return "";
		}
		if (format == null) {
			format = PATTERND;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}

	/**
	 * 将指定年,月,日的日期转为字符型,格式为yyyy-MM-dd
	 * @param
	 * @return
	 */
	public static String dateToString(int year, int month, int day, String pattern) {
		return dateToString(getDate(year, month, day), pattern);
	}

	/**
	 * 将指定字符型日期转为日期型,,格式为指定的pattern
	 * @param
	 * @return
	 */
	public static Date stringToDate(String string, String pattern) {
		SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance();
		format.applyPattern(pattern);
		try {
			return format.parse(string);
		} catch (ParseException e) {
		    e.printStackTrace();
			return null;
		}
	}

	/**
	 * 将指定字符型日期转为日期型,指定格式为yyyy-MM-dd
	 * @param
	 * @return
	 */
	public static Date stringToDate(String string) {
		return stringToDate(string, PATTERNA);
	}

	/**
	 * 获得两个日期之间间隔的天数
	 *
	 * @param startDate
	 *            起始年月日
	 * @param endDate
	 *            结束年月日
	 * @return int
	 */
	public static int getDays(Date startDate, Date endDate) {
		int elapsed = 0;
		Calendar cal = Calendar.getInstance();
		cal.setTime(startDate);
		Date d1 = cal.getTime();

		cal.setTime(endDate);
		Date d2 = cal.getTime();

		long daterange = d2.getTime() - d1.getTime();
		// 一天的毫秒数
		long time = 1000 * 3600 * 24;
		elapsed = (int) (daterange / time);
		return elapsed;
	}

	/**
	 * 是否是工作时间
	 * @param date
	 * @param startTimeIn
	 * @param endTimeIn
	 * @return
	 */
	public static boolean isWorkHour(Date date, String startTimeIn, String endTimeIn) {
		String startTime = startTimeIn;
		String endTime = endTimeIn;
		if (StringUtils.isEmpty(startTime)) {
			startTime = "0800";
		}
		if (StringUtils.isEmpty(endTime)) {
			endTime = "2200";
		}
		int start = Integer.parseInt(startTime);
		int end = Integer.parseInt(endTime);
		int hour = getDateHour(date);
		int m = getDateMinute(date);
		String hstr = hour <= 9 ? "0" + hour : hour + "";
		String mstr = m <= 9 ? "0" + m : m + "";
		int dateInt = Integer.parseInt(hstr + mstr);
		if (dateInt >= start && dateInt <= end) {
			return true;
		}
		return false;
	}

	/**
	 * 根据传入日期，返回此月有多少天
	 * @param date 格式为 201408
	 * @return
	 */
	public static int getDayOfMonth(String date) {
		int year = Integer.parseInt(date.substring(0, 3));
		int month = Integer.parseInt(date.substring(date.length() - 1, date.length()));

		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		// Java月份才0开始算 6代表上一个月7月
		cal.set(Calendar.MONTH, month - 1);
		int dateOfMonth = cal.getActualMaximum(Calendar.DATE);
		return dateOfMonth;
	}

	/**
	 * 取指定日期月份前一月
	 * @param
	 * @return
	 */
	public static int getLastDateMonth(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.MONTH);
	}

	/**
	 * 取日期的当前月第一天
	 */
	public static Date getMonthFirstDay(Date date) {
		return getDate(getDateYear(date), getDateMonth(date), 1);
	}

	/**
	 * 取日期的当前月最后一天
	 * @param date
	 * @return
	 */
	public static Date getMonthLastDay(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.add(Calendar.MONTH, 1);
		calendar.add(Calendar.DAY_OF_MONTH, -1);
		Date lastDayOfMonth = calendar.getTime();
		return lastDayOfMonth;
	}

	/**
	 * 前月第一天
	 * @param date
	 * @return Date
	 */
	public static Date getLastDateMonthDay(Date date) {
		return getDate(getDateYear(date), getLastDateMonth(date), 1);
	}

	/**
	 * 给时间增加秒数
	 *
	 * @param date
	 * @param intervalTime
	 * @return
	 */
	public static Date addSecond(Date date, int intervalTime) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.SECOND, intervalTime);
		return calendar.getTime();
	}

	/**
	 * 获取当前时间相加减intervalTime秒之后的时间
	 * @param date
	 * @param intervalTime
	 * @return
	 */
	public static Date subSecond(Date date, int intervalTime) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.SECOND, calendar.get(Calendar.SECOND) - intervalTime);
		return calendar.getTime();
	}

	/**
	 * 给一个时间增加天
	 *
	 * @param dateStr
	 *            日期时间
	 * @param n
	 *            增加天数
	 * @return
	 */
	public static String addDay(String dateStr, int n) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar cd = Calendar.getInstance();
			cd.setTime(sdf.parse(dateStr));
			cd.add(Calendar.DATE, n);
			return sdf.format(cd.getTime());
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 给一个时间增加天
	 * @param startDate 日期
	 * @param n
	 * @return
	 */
	public static Date addDay(Date startDate, int n) {
		Calendar cd = Calendar.getInstance();
		cd.setTime(startDate);
		cd.add(Calendar.DATE, n);
		return cd.getTime();
	}

	/**
	 * 给一个时间减天数
	 * @param dateStr 日期时间
	 * @param n 减少天数
	 * @return
	 */
	public static String subDay(String dateStr, int n) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar cd = Calendar.getInstance();
			cd.setTime(sdf.parse(dateStr));
			cd.set(Calendar.DATE, cd.get(Calendar.DATE) - Math.abs(n));
			return sdf.format(cd.getTime());
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 给一个时间减天数
	 * @param date
	 * @param n
	 * @return
	 */
	public static Date subDay(Date date, int n) {
		try {
			Calendar cd = Calendar.getInstance();
			cd.setTime(date);
			cd.set(Calendar.DATE, cd.get(Calendar.DATE) - Math.abs(n));
			return cd.getTime();
		} catch (Exception e) {
			return null;
		}
	}


	/**
	 * 两个日期比较大小
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static int compareDate(String date1, String date2) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date dt1 = df.parse(date1);
			Date dt2 = df.parse(date2);
			if (dt1.getTime() > dt2.getTime()) {
				return 1;
			} else if (dt1.getTime() < dt2.getTime()) {
				return -1;
			} else {
				return 0;
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return 0;
	}

	/**
	 * 给时间增加分数
	 * @param date 时间
	 * @param n 增加值
	 * @return
	 */
	public static Date addMinute(Date date, int n) {
		try {
			Calendar cd = Calendar.getInstance();
			cd.setTime(date);
			cd.add(Calendar.MINUTE, n);
			return cd.getTime();
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 给码数日期计算出这周的第一天和最后一天
	 * @param dataStr 传入的参数
	 * @param dateFormat 参数格式化
	 * @return resultDateFormat 返回时的格式，结果用 ; 隔开
	 */
	public static String getWeekFirstAndEndDay(String dataStr, String dateFormat, String resultDateFormat) {
		Calendar cal = Calendar.getInstance();
		try {
			cal.setTime(new SimpleDateFormat(dateFormat).parse(dataStr));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		int d = 0;
		if (cal.get(Calendar.DAY_OF_WEEK) == 1) {
			d = -6;
		} else {
			d = 2 - cal.get(Calendar.DAY_OF_WEEK);
		}
		cal.add(Calendar.DAY_OF_WEEK, d);
		// 所在周开始日期
		String data1 = new SimpleDateFormat(resultDateFormat).format(cal.getTime());
		cal.add(Calendar.DAY_OF_WEEK, 6);
		// 所在周结束日期
		String data2 = new SimpleDateFormat(resultDateFormat).format(cal.getTime());
		return data1 + ";" + data2;
	}

	public static String getBeforeWeekFirstAndLastDay(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(PATTERNA);
		Calendar beforeWeekSundayCal = Calendar.getInstance();
		beforeWeekSundayCal.setTime(new Date());
		int day = beforeWeekSundayCal.get(Calendar.DAY_OF_WEEK);
		beforeWeekSundayCal.add(Calendar.DATE, beforeWeekSundayCal.getFirstDayOfWeek() - day);
		String beforeLastDay = sdf.format(beforeWeekSundayCal.getTime());
		beforeWeekSundayCal.add(Calendar.DATE, -6);
		String beforeFirstDay = sdf.format(beforeWeekSundayCal.getTime());
		return beforeFirstDay + ";" + beforeLastDay;
	}

	/**
	 * 返回前几个月的当天的后一天
	 * @param mon 传入的参数
	 * @return String
	 */
	public static String getBeforeMonthByNow(int mon, int day) {
		//日历对象
		Calendar calendar = Calendar.getInstance();
		//设置当前日期
		calendar.setTime(new Date());
		//月份减一
		calendar.add(Calendar.MONTH, -mon);
		//天数加一
		calendar.add(Calendar.DATE, day);
		return DateUtils.formateDate(calendar.getTime());
	}

	public static Map<String, Object> getLikeNowDayDates() {
		Map<String, Object> selectMap = new HashMap<String, Object>();
		Date nowDate = DateUtils.getDate();
		selectMap.put("nowDate", DateUtils.formateDate(nowDate));
		selectMap.put("nowDateSubYear", DateUtils.formateDate(nowDate).substring(5));
		selectMap.put("yesterDay", DateUtils.formateDate(DateUtils.subDay(nowDate, 1)));
		selectMap.put("yesterDaySubYear", DateUtils.formateDate(DateUtils.subDay(nowDate, 1)).substring(5));
		String[] nowWeek = DateUtils
				.getWeekFirstAndEndDay(DateUtils.formateDate(nowDate), DateUtils.PATTERNA, DateUtils.PATTERNA)
				.split(";");
		selectMap.put("nowWeek", nowWeek[0].trim() + "~" + nowWeek[1].trim());
		selectMap.put("nowWeekSubYear", nowWeek[0].trim().substring(5) + "~" + nowWeek[1].trim().substring(5));
		String[] beforeWeek = DateUtils.getBeforeWeekFirstAndLastDay(nowDate).split(";");
		selectMap.put("beforeWeek", beforeWeek[0].trim() + "~" + beforeWeek[1].trim());
		selectMap.put("beforeWeekSubYear", beforeWeek[0].trim().substring(5) + "~" + beforeWeek[1].trim().substring(5));
		String nowMonthFirstDate = DateUtils.formateDate(DateUtils.getMonthFirstDay(nowDate));
		String nowMonthLastDate = DateUtils.formateDate(DateUtils.getMonthLastDay(nowDate));
		selectMap.put("nowMonth", nowMonthFirstDate.trim() + "~" + nowMonthLastDate);
		selectMap.put("nowMonthSubYear", nowMonthFirstDate.trim().substring(5) + "~" + nowMonthLastDate.substring(5));
		Date beforMonthFirstDay = DateUtils.getLastDateMonthDay(nowDate);
		String beforMonthFirstDay1 = DateUtils.formateDate(beforMonthFirstDay);
		String beforMonthLastDay1 = DateUtils.formateDate(DateUtils.getMonthLastDay(beforMonthFirstDay));
		selectMap.put("beforeMonth", beforMonthFirstDay1 + "~" + beforMonthLastDay1);
		selectMap.put("beforeMonthSubYear", beforMonthFirstDay1.substring(5) + "~" + beforMonthLastDay1.substring(5));
		return selectMap;
	}

	public static Map<String, String> weixinsGetLikeNowDayDates() {
		Map<String, String> selectMap = new HashMap<String, String>();
		Date nowDate = DateUtils.getDate();
		String nowDateString = DateUtils.formateDate(nowDate);
		//当天
		selectMap.put("nowDate", nowDateString);
		selectMap.put("nowDateSubYear", nowDateString.substring(5));
		//昨天
		selectMap.put("yesterDay", DateUtils.formateDate(DateUtils.subDay(nowDate, 1)));
		selectMap.put("yesterDaySubYear", DateUtils.formateDate(DateUtils.subDay(nowDate, 1)).substring(5));
		//本周	
		String[] nowWeek = new String[2];
		nowWeek[0] = DateUtils.subDay(nowDateString, 6);
		nowWeek[1] = nowDateString;
		selectMap.put("nowWeek", nowWeek[0].trim() + "~" + nowWeek[1].trim());
		selectMap.put("nowWeekSubYear", nowWeek[0].trim().substring(5) + "~" + nowWeek[1].trim().substring(5));
		//上周	
		String[] beforeWeek = new String[2];
		beforeWeek[0] = DateUtils.subDay(nowDateString, 13);
		beforeWeek[1] = DateUtils.addDay(beforeWeek[0], 6);
		selectMap.put("beforeWeek", beforeWeek[0].trim() + "~" + beforeWeek[1].trim());
		selectMap.put("beforeWeekSubYear", beforeWeek[0].trim().substring(5) + "~" + beforeWeek[1].trim().substring(5));
		//本月
		String nowMonthFirstDate = getBeforeMonthByNow(1, 1);
		selectMap.put("nowMonth", nowMonthFirstDate.trim() + "~" + nowDateString);
		selectMap.put("nowMonthSubYear", nowMonthFirstDate.trim().substring(5) + "~" + nowDateString.substring(5));
		//上月
		String beforeMonthFirstDate = getBeforeMonthByNow(2, 1);
		String beforeMonthEndDate = getBeforeMonthByNow(1, 0);
		selectMap.put("beforeMonth", beforeMonthFirstDate + "~" + beforeMonthEndDate);
		selectMap.put("beforeMonthSubYear", beforeMonthFirstDate.substring(5) + "~" + beforeMonthEndDate.substring(5));
		return selectMap;
	}

	/**
	 * 分钟差
	 * @param from
	 * @param to
	 * @return
	 */
	public static int disMinutes(Date from, Date to) {
		int minutes = (int) ((to.getTime() - from.getTime()) / (1000 * 60));
		return minutes;
	}

	/**
	 * 小时差
	 * @param from
	 * @param to
	 * @return
	 */
	public static int disHours(Date from, Date to) {
		int hours = (int) ((to.getTime() - from.getTime()) / (1000 * 60 * 60));
		return hours;
	}

	/**
	 * 天数差
	 * @param from
	 * @param to
	 * @return
	 */
	public static int disDays(Date from, Date to) {
		int days = (int) ((to.getTime() - from.getTime()) / (1000 * 60 * 60 * 24));
		return days;
	}

	/**
	 * 获取两个日期之间的日期
	 *
	 * @param startTime
	 *            起始日期
	 * @param endTime
	 *            结束日期
	 * @return
	 * @throws ParseException
	 */
	@SuppressWarnings("unused")
	public static List<String> getDates(Date startTime, Date endTime) {
		List<String> dates = new ArrayList<String>();
		Date now = new Date();
		String thisDate = DateUtils.formateDate(now);
		String firstDate = "";
		if (startTime != null) {
			firstDate = DateUtils.formateDate(startTime);
		} else {
			firstDate = DateUtils.subDay(thisDate, 2);
		}
		String lastDate = "";
		if (endTime != null) {
			lastDate = DateUtils.formateDate(endTime);
		} else {
			lastDate = DateUtils.formateDate(now);
		}
		int num = DateUtils.compareDate(firstDate, lastDate);
		if (num != 1) {
			dates.add(firstDate);
			while (!firstDate.equals(lastDate)) {
				firstDate = DateUtils.addDay(firstDate, 1);
				dates.add(firstDate);
			}
		} else {
		}
		return dates;
	}

	/**
	 * 取日期的当前月第一天
	 */
	public static String getMonthFirstDay(String date,String pattern) {
		if (StringUtils.isEmpty(date)){
			return "";
		}
		Date date1 = getDate(getDateYear(stringToDate(date,PATTERNH)), getDateMonth(stringToDate(date,PATTERNH)), 1);
		return dateToString(date1,pattern);
	}

	/**
	 * 取日期的当前月最后一天
	 * @param date
	 * @return
	 */
	public static String getMonthLastDay(String date,String pattern) {
		if (StringUtils.isEmpty(date)){
			return "";
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(stringToDate(date,PATTERNH));
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.add(Calendar.MONTH, 1);
		calendar.add(Calendar.DAY_OF_MONTH, -1);
		Date lastDayOfMonth = calendar.getTime();
		return dateToString(lastDayOfMonth,pattern);
	}

    public static void main(String[] args) {
        System.out.println(DateUtils.stringToDate("2018/6/7 12:30:00", DateUtils.PATTERNJ));
    }



}
